## Figure A3 - Memebers ARN###

library(foreign)
library(readstata13)
library(ggplot2)

# Data
forresults <- read.dta13("~/Dropbox/Replication_MVC/Datasets/datasets_analysis/panel_excombatientes.dta")

#keep obv from 2016
forresults2016 <- forresults[ which(forresults$year=="2016"),]
ExestructuraNumero <- table(forresults2016$Exestructura)
CARGONumero <- table(forresults2016$CARGO)

# Data with freq
both <- table(forresults2016$Exestructura, forresults2016$CARGO)
both <- data.frame(both)

# Remove large groups
both <- both[which(both$Var2!="Patrullero" & both$Freq>1),]

# Rename some positions for viz
both$Var2new <- gsub("Comandante De Urbanos O Comandante De Milicias Urbanas", "Comandante Urbano", both$Var2)
both$Var2new2 <- gsub("Comandante De Finanzas O Financiero", "Comandante Finanzas", both$Var2new)
both$Var2new23 <- gsub("Colaborador Y/O Informante", "Informante", both$Var2new2)

# Plot
membersARN <- ggplot(both, aes(x = Var2new23, y = Var1)) + geom_tile(aes(fill = Freq)) + scale_fill_gradient(name = 'Number of Members', low = 'white', high = 'blue') + theme(axis.title.y = element_blank()) + theme(axis.title.x = element_blank()) + theme(axis.text.x = element_text(angle = 45, hjust = 1))

